package cn.sytton.taffecloud.serivce.auth.security.model;

import cn.sytton.taffecloud.common.base.security.LoginUser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 登录用户(UserDetails)
 *
 * @author skyrock
 */
public class SecurityUser implements UserDetails {

    private final LoginUser loginUser;

    public SecurityUser(LoginUser loginUser) {
        this.loginUser = loginUser;
    }

    public LoginUser getLoginUser() {
        return loginUser;
    }

    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.loginUser.getPassword();
    }

    @JsonIgnore
    @Override
    public String getUsername() {
        //这是给SpringSecurity框架用的
        return this.loginUser.getLoginName();
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return true;
    }
}
